package kahuuFotos.test;

import java.io.File;
import javax.ws.rs.core.MediaType;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.multipart.FormDataBodyPart;
import com.sun.jersey.multipart.FormDataMultiPart;
import com.sun.jersey.multipart.file.FileDataBodyPart;

/**
 * 
 * @author gustavolozano
 *
 */
public class KahuuClient 
{

	//------------------------------------------------------------------------------------
	// Metodos
	//------------------------------------------------------------------------------------

	public String  testAgregarFoto(String nombre, String comentario, String pos, File file) 
	{
		Client client = Client.create();

		WebResource r = client.resource("http://50.56.241.227:8080/KahuuFotosRest/rest/fotos/");

		FormDataMultiPart fdmp = new FormDataMultiPart(); 
		fdmp.bodyPart(new FormDataBodyPart("nombre", nombre)); 
		fdmp.bodyPart(new FormDataBodyPart("comentarios", comentario)); 
		fdmp.bodyPart(new FormDataBodyPart("posicion", pos)); 
		fdmp.bodyPart(new FileDataBodyPart("file", file, MediaType.APPLICATION_OCTET_STREAM_TYPE)); 

		String response = r.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(String.class, fdmp);               
		return response;
	}


	public String testVerFotos(String pos)
	{
		Client client = Client.create();

		WebResource r = client.resource("http://localhost:8080/KahuuFotosRest/rest/fotos/");		
		String response = r.queryParam("posicion", pos).get(String.class);

		return response;
	}

	public String testSimilar(File file)
	{
		Client client = Client.create();

		WebResource r = client.resource("http://localhost:8080/KahuuFotosRest/rest/fotos/");		
		String response = r.queryParam("ancho", "20").get(String.class);

		return response;
	}
	
	public static void main(String[] args)
	{
		File f = new File("/Users/gustavolozano/Desktop/3-1.jpg");
		KahuuClient kahuu = new KahuuClient();
		System.out.println(kahuu.testAgregarFoto("Prueba1", "COmentario 1", "ML",f));
		 
	}

}
